package com.cwnu.onlinemall.service;
import ch.qos.logback.core.net.SyslogOutputStream;
import com.cwnu.onlinemall.mapper.MallAccountMapper;
import com.cwnu.onlinemall.pojo.MallAccount;
import com.cwnu.onlinemall.pojo.MallAccountExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class accountServiceImpl implements accountService{
    @Autowired
    MallAccountMapper mallAccountMapper;
    @Override
    public List<MallAccount> selectAll() {
        return mallAccountMapper.selectByExample(null);
    }

    @Override
    public MallAccount selectById(Integer id) {
        return mallAccountMapper.selectByPrimaryKey(id);
    }


    @Override
    public Integer deleteaccountById(Integer id) {
        return mallAccountMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Integer insertaccount(MallAccount mallAccount) {
        int row = mallAccountMapper.insertSelective(mallAccount);
        return row;
    }

    @Override
    public Integer updateaccount(MallAccount mallAccount) {
        int row = mallAccountMapper.updateByPrimaryKeySelective(mallAccount);
        return row;
    }

    @Override
    public List<MallAccount> login(MallAccount mallAccount) {
        MallAccountExample Example = new MallAccountExample();
        MallAccountExample.Criteria criteria = Example.or();
        criteria.andAccountAccountEqualTo(mallAccount.getAccountAccount());
        criteria.andAccountPasswordEqualTo(mallAccount.getAccountPassword());
//        System.out.println(Example);
        List<MallAccount> mallAccount1 = mallAccountMapper.selectByExample(Example);
        return mallAccount1;
    }

    @Override
    public List<MallAccount> selectByaccount(MallAccount mallAccount) {
        MallAccountExample Example = new MallAccountExample();
        MallAccountExample.Criteria criteria = Example.or();
        criteria.andAccountAccountEqualTo(mallAccount.getAccountAccount());
        List<MallAccount> mallAccount1 = mallAccountMapper.selectByExample(Example);
        return mallAccount1;
    }
}
